﻿using Resto.CostControl.Core.Facade.DishOrderModule.FacadeObject;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Resto.CostControl.Core.Facade.DishOrderModule.DataTransferObject;
using Enterprise.Framework.Core.Container;
using Resto.CostControl.Core.Enums;
using System.Collections.Generic;
using Resto.CostControl.Core.Domain.Model;

namespace Resto.CostControl.UnitTest
{
    
    
    /// <summary>
    ///这是 DishOrderFOTest 的测试类，旨在
    ///包含所有 DishOrderFOTest 单元测试
    ///</summary>
    [TestClass()]
    public class DishOrderFOTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///AddDishOrder 的测试
        ///</summary>
        [TestMethod()]
        public void AddDishOrderTest()
        {
            DishOrderFO target = ObjectCreator.Create<DishOrderFO>();

            List<DishOrderItemDTO> list = new List<DishOrderItemDTO>();
            for (int k = 1; k < 6; k++)
            {
                DishOrderItemDTO item = new DishOrderItemDTO(k);
                item.Count = 10;

                list.Add(item);
            }

            DishOrderDTO orderDTO = new DishOrderDTO()
            {
                SiteId = 1,
                OrderDate = DateTime.Now,
                OrderType = DishOrderType.Normal,
                Items = list.ToArray(),
            };

            target.AddDishOrder(orderDTO);
            
        }

        /// <summary>
        ///UpdateDishOrder 的测试
        ///</summary>
        [TestMethod()]
        public void UpdateDishOrderTest()
        {
            DishOrderFO target = ObjectCreator.Create<DishOrderFO>();

            List<DishOrderItemDTO> list = new List<DishOrderItemDTO>();
            for (int k = 1; k < 6; k++)
            {
                DishOrderItemDTO item = new DishOrderItemDTO(k);
                item.Count = 10;

                list.Add(item);
            }

            DishOrderDTO orderDTO = new DishOrderDTO()
            {
                SiteId = 1,
                OrderDate = DateTime.Now,
                OrderType = DishOrderType.Normal,
                Items = list.ToArray(),
            };

            target.AddDishOrder(orderDTO);

            List<DishOrderItemDTO> list2 = new List<DishOrderItemDTO>();
            for (int k = 1; k < 6; k++)
            {
                DishOrderItemDTO item = new DishOrderItemDTO(k);
                item.Count = 10;

                list2.Add(item);
            }

            orderDTO.Items = list2.ToArray();

            target.UpdateDishOrder(orderDTO);
        }

        [TestMethod]
        public void AddWeekDishOrderTest()
        {
            DishOrderFO target = ObjectCreator.Create<DishOrderFO>();

            WeekDishOrderDTO weekDTO = new WeekDishOrderDTO()
            {
                BeginDate = DateTime.Now,
                EndDate = DateTime.Now.AddDays(7),
                SiteId = 1,
            };
            

            List<DishOrderDTO> list2 = new List<DishOrderDTO>();
            for (int i = 0; i < 7; i++)
            {
                List<DishOrderItemDTO> list = new List<DishOrderItemDTO>();
                for (int k = 1; k < 6; k++)
                {
                    DishOrderItemDTO item = new DishOrderItemDTO(k);
                    item.Count = 10;

                    list.Add(item);
                }

                DishOrderDTO orderDTO = new DishOrderDTO()
                {
                    SiteId = 1,
                    OrderDate = DateTime.Now.AddDays(i),
                    OrderType = DishOrderType.Normal,
                    Items = list.ToArray(),
                };

                list2.Add(orderDTO);
                //target.AddDishOrder(orderDTO);
            }

            target.AddWeekDishOrder(weekDTO, list2.ToArray());
        }

        [TestMethod]
        public void UpdateWeekDishOrderTest()
        {
            DishOrderFO target = ObjectCreator.Create<DishOrderFO>();

            WeekDishOrderDTO weekDTO;
            DishOrderDTO[] items;

            weekDTO = target.GetWeekDishOrderDTO(1,out items);

            items[0].Items[0].Count = 100;

            target.UpdateWeekDishOrder(weekDTO, items);
        }
    }
}
